<?

class Vakanz_Letter extends Vakanz_CRM_Db_Table_Row {
	protected $_prefix = 'letter';

	function isExisting() {
		return false;
	}
	public function save() {
		if ($this->offsetGet(current($this->getTable()->info('primary'))) > 0) {
			$this->{$this->_prefix.'_valid_till'} = date('Y-m-d H:i:s');
			$this->{$this->_prefix.'_status'} = 3;
			$data = $this->toArray();
			parent::save();
			unset($data[$this->_prefix.'_autoid']);
			unset($data[$this->_prefix.'_valid_till']);
			unset($data[$this->_prefix.'_valid_from']);
			unset($data[$this->_prefix.'_status']);
			$letter = $this->getTable()->createRow($data);
			$letter_autoid = $letter->save();
			return $letter_autoid;
		} else {
			if (empty($this->letter_id)) {
				$this->letter_id = $this->getTable()->getNewId('letter_id');
			}
			return parent::save();
		}
	}

}